package com.mlh.furn.service.impl;

import com.mlh.furn.bean.Furn;
import com.mlh.furn.bean.FurnExample;
import com.mlh.furn.dao.FurnMapper;
import com.mlh.furn.service.FurnService;
import jdk.nashorn.internal.runtime.regexp.JoniRegExp;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FurnServiceImpl implements FurnService {
	//注入FurnMapper接口对象（代理对象）
	@Resource
	private FurnMapper furnMapper;
	@Override
	public void save(Furn furn) {
		//1.使用insertSelective
		//2.因为我们的furn表的id是自增的,所以使用insertSelective方法
		System.out.println(furn);
		furnMapper.insertSelective(furn);
	}
	@Override
	public List<Furn> findAll() {
		// 查看分FurnMapper.xml文件
		//传入是null,表示返回所有的家居信息
		return furnMapper.selectByExample(null);
	}

	@Override
	public void update(Furn furn) {
		furnMapper.updateByPrimaryKeySelective(furn);
	}

	@Override
	public void del(Integer id) {
		furnMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Furn findOne(Integer id) {
		return furnMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Furn> findByCondition(String name) {
		FurnExample furnExample=new FurnExample();
		FurnExample.Criteria criteria = furnExample.createCriteria();
		// 判断name是否有具体的内容
		if(StringUtils.hasText(name)){
			criteria.andNameLike("%" + name + "%");
		}
		// 如果name没有传值null， ""，"  "， 依然是查询所有的记录
		return furnMapper.selectByExample(furnExample);
	}


}